package com.xframe.common.config;



import com.xframe.common.core.aop.BaseDecoration;
import com.xframe.common.core.aop.XAOPRuntime;
import com.xframe.xdal.core.util.XReflect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
public class AOPConfiguration {

    @Bean
    public AOPConfigBean aopConfigBeanFactory() {

        this.aopConfigBean = new AOPConfigBean();
        return this.aopConfigBean;
    }

    private AOPConfigBean aopConfigBean;

    @Bean
    public XAOPRuntime aopRuntimeFactory() {
        if(aopConfigBean.hasValue()){
            for(DecorationConfig decorationConfig : aopConfigBean.getDecorationConfigs()){
                BaseDecoration decoration = BaseDecoration.create(decorationConfig);
                XAOPRuntime.getInstance().registerDecoration(decoration);
            }
        }
        return XAOPRuntime.getInstance();
    }
}
